// 引入接口文件
import { getMember, downLoadFile, authorizeTime } from './evaluateListServ.js'

// 对象和JSON字符串互转
import { parse } from 'qs'
// 弹出消息框
import { message } from 'antd'
// 日期处理对象
import moment from 'moment'
/* isEmpty 对象是否为空
 * isArray 对象是否数组
 * cloneDeep 对象深拷贝
 */
import { isEmpty, isArray, cloneDeep, merge } from 'lodash'
// 引入路由对象
import { hashHistory } from 'dva/router'
import { download } from 'utils/util'
import Item from 'antd/lib/list/Item';

// 初始默认状态
const defultState = {
  loading: false,
  btnLoading: false,
  showModal: false,
  consultantId: '',
  biz: {
    queryForm: {},
    selectedRows: []
  },
}

// 声明module
const tmpModule = {
  namespace: 'evaluateListModel',
  state: cloneDeep(defultState),
  subscriptions: {
    setup ({dispatch, history}) {
      history.listen(({pathname, query}) => {
        let {actionType, contentId} = query
        if ('' + tmpModule.pathname === '' + pathname) {
          //每次进来页面更新数据 重置state
          
          
        }
      })
    },
  },
  
  // 方法列表
  effects: {
    // 查询记录
    
    * downLoad ({payload}, {put, call, select}) {
      try {
        let tmpState = yield select(state => state[tmpModule.namespace])
        let {queryForm} = tmpState.biz
        const {data, success} = yield call(downLoadFile, queryForm)
        if (success) {
          // yield put({ type: 'updateStore', payload: {  data } });
          // window.open(data);
          message.success('操作成功')
          let url = data || ''
          if (url) {
            download(url)
          }
        }
      } catch (e) {
        console.error(e)
      }
    },
    *deleteEvaluate({payload}, {put, call, select}) {
      try{
        let tmpState = yield select(state => state[tmpModule.namespace])
        console.log(payload)
        const {data, success} = yield call(authorizeTime,payload)
        if(success){
          message.success('删除成功')
          tmpState.biz.refreshListDatas(true)
        }
      } catch(e){
        console.error(e)
      }
    }
  },
  // 存入状态机
  reducers: {
    updateStore (preState, action) {
      return Object.assign({}, preState, action.payload)
    },
  }
  
}

export default tmpModule
